﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.Xpo;

namespace POI.eTransmittal.Enitity
{
   public class DocumentType:XPCustomObject
    {
       const string DATE_EXPRESSION = "[yymm]";
       const string SEQUENCE_EXPRESSION = "[sequence]";
       const string CODE_EXPRESSION = "[code]";
      [Key]
       public string Code;
       public string TypeName;
       public string Formula;
       public string Description;
       public DocumentType(Session session)
           : base(session)
       {

       }
       #region AuditTrail

       public DateTime CreatedDate;

       public string CreatedBy;

       public DateTime LastChangedDate;

       public string LastChangedBy;

       public void Save(string userId)
       {
           if (CreatedBy == null || CreatedDate == DateTime.MinValue)
           {
               this.CreatedDate = DateTime.Now;
               this.CreatedBy = userId;
           }

           this.LastChangedDate = DateTime.Now;
           this.LastChangedBy = userId;

           this.Save();
       }

       #endregion

       public string GenerateRefNumber(int p)
       {
           string dateExp = DateTime.Today.ToString("yyMM");
           return Formula.Replace(DATE_EXPRESSION,dateExp).Replace(SEQUENCE_EXPRESSION,p.ToString()).Replace(CODE_EXPRESSION,Code);

       }
    }
}
